package com.dmai.capacity.platform.common.model;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * 客户开通资源包表
 *
 * @author
 * @email
 * @date 2024-03-29 21:14:28
 */

@Data
public class OauthUserPackage implements Serializable {
    private static final long serialVersionUID = 1L;


    private Integer id;

    private Integer userid;

    private Integer packageId;

    @TableField(exist = false)
    private Integer capabilityId;

    private Integer type;

    private Date expiredTime;

    private Integer count;

    private Integer quotaTotal;

    private Integer quotaAvailable;

    private Date applyTime;

    private Integer hasPaid;

    private Date paidTime;

    private Integer effective;

    @TableField(exist = false)
    private CapabilityPackage refrence;


    public OauthUserPackage(Integer userid, Integer packageId) {
        this.userid = userid;
        this.packageId = packageId;
    }

    public OauthUserPackage buy(CapabilityPackage capabilityPackage, Integer count, Integer hasPaid,Date paidTime) {
        this.capabilityId = capabilityPackage.getCapabilityId();
        this.type = capabilityPackage.getType();
        this.count = count;
        this.quotaTotal = capabilityPackage.getQuota() * count;
        this.quotaAvailable = capabilityPackage.getQuota() * count;
        this.applyTime = new Date();
        this.hasPaid=hasPaid;
        this.paidTime=paidTime;
        this.effective = 1;
        this.refrence = capabilityPackage;

        return this;
    }


}
